function mv = mainver
% mainver  - get matlab main version
%
% FORMAT:       mv = mainver
%
% Output Fields:
%
%       mv          numeric main version number
%
% See also ver, version

% Version:  v0.5c
% Build:    6120415
% Date:     Dec-04 2006, 3:15 PM CET
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% get version info?
persistent mainver_ver;
if isempty(mainver_ver)
    mv_temp = ver('matlab');
    if isempty(mv_temp) || ...
       ~isstruct(mv_temp)
        warning( ...
            'BVQXtools:InternalError', ...
            'Error getting MATLAB version number.' ...
        );
        mainver_ver = 6;
        mv = 6;
        return;
    end
    mv_temp = mv_temp(1).Version;
    mv_ivchar = find(mv_temp < 48 | mv_temp > 57);
    if ~isempty(mv_ivchar)
        mv_temp(mv_ivchar(1):end) = [];
    end
    if ~isempty(mv_temp)
        mainver_ver = str2double(mv_temp);
    else
        mainver_ver = 6;
        warning( ...
            'BVQXtools:InternalError', ...
            'Error getting MATLAB version number.' ...
        );
    end
end

% return version info
mv = mainver_ver;
